﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace AfterlifeLib
{
    /// <summary>
    /// Static class used to convert between data types and strings.
    /// </summary>
    public static class Converter
    {
        /// <summary>
        /// Converts a Microsoft.Xna.Framework.Graphics.Color to a string.
        /// </summary>
        /// <param name="color">The Color to convert.</param>
        /// <returns></returns>
        public static string ColorToString(Color color)
        {
            return string.Format("{0} {1} {2} {3}", color.R, color.G, color.B, color.A);
        }

        /// <summary>
        /// Converts a string to a Microsoft.Xna.Framework.Graphics.Color.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns></returns>
        public static Color StringToColor(string s)
        {
            string[] parts = s.Split(' ');

            return new Color(byte.Parse(parts[0]), byte.Parse(parts[1]), byte.Parse(parts[2]), byte.Parse(parts[3]));
        }

        /// <summary>
        /// Converts a Microsoft.Xna.Framework.Vector3 to a string.
        /// </summary>
        /// <param name="vector3">The Vector3 to convert.</param>
        /// <returns></returns>
        public static string Vector3ToString(Vector3 vector3)
        {
            return string.Format("{0} {1} {2}", vector3.X, vector3.Y, vector3.Z);
        }

        /// <summary>
        /// Converts a string to a Microsoft.Xna.Framework.Vector3.
        /// </summary>
        /// <param name="vector3">The string to convert.</param>
        /// <returns></returns>
        public static Vector3 StringToVector3(string s)
        {
            string[] parts = s.Split(' ');

            return new Vector3(float.Parse(parts[0]), float.Parse(parts[1]), float.Parse(parts[2]));
        }
    }
}
